package com.umanji.building.service;

import java.util.ArrayList;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.umanji.building.domain.BuildingInfos;
import com.umanji.building.domain.Buildings;
import com.umanji.building.domain.PublicOfficialBuildings;
import com.umanji.generic.service.GenericService;

@Service("buildingService")
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class BuildingServiceImpl extends GenericService<Buildings, Long> implements BuildingService {

	private final Log log = LogFactory.getLog ( BuildingServiceImpl.class );

    public Buildings findByBuildingNo(String no) {
    	log.debug("building no ::::::::::::::::::::::::::::::: " + no);
    	// return (Tbbi001) em.createQuery("from " + Tbbi001.class.getSimpleName()).getSingleResult();
    	return (Buildings) em.createQuery("Select t from " + Buildings.class.getSimpleName() + " t where t.buildingNo = :no").setParameter("no", no).getSingleResult();
    }

    public PublicOfficialBuildings findByPobNo(String no) {
    	log.debug("public official building no ::::::::::::::::::::::::::::::: " + no);
    	// return (Tbbi001) em.createQuery("from " + Tbbi001.class.getSimpleName()).getSingleResult();
    	return (PublicOfficialBuildings) em.createQuery("Select t from " + PublicOfficialBuildings.class.getSimpleName() + " t where t.buildingNo = :no").setParameter("no", no).getSingleResult();
    }
    
    public List findByBuildingId(Long id){
    	return super.em.createQuery("Select t from " + BuildingInfos.class.getSimpleName() + " t join t.building b where b.id = :building_id").setParameter("building_id", id).getResultList();
    }
}
